package v2;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class DecorationIMenu implements  IMenu {
    private List<Matter>  matters=new ArrayList<>();

    private BigDecimal bigDecimal=BigDecimal.ZERO;

    // 装修面积
    private BigDecimal area;

    // 装修等级
    private Integer level;
    private DecorationIMenu(){

    }

    public DecorationIMenu(BigDecimal area, Integer level){
        this.area=area;
        this.level=level;
    }

    @Override
    public IMenu appendCelling(Matter matter) {
        this.matters.add(matter);
        this.bigDecimal=bigDecimal.add(area.multiply(new BigDecimal("0.2")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendCoat(Matter matter) {
        this.matters.add(matter);
        this.bigDecimal=bigDecimal.add(area.multiply(new BigDecimal("1.4")).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendFloor(Matter matter) {
        this.matters.add(matter);
        this.bigDecimal=bigDecimal.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendTile(Matter matter) {
        matters.add(matter);
        bigDecimal = bigDecimal.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public String getDetail() {
        StringBuilder detail = new StringBuilder("\r\n--------------------" +
                "-----------------------------------\r\n" +

                "装修清单" + "\r\n" +

                "套餐等级：" + level + "\r\n" +

                "套餐价格：" + bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP) +

                " 元\r\n" +

                "房屋⾯积：" + area.doubleValue() + " 平⽶\r\n" +

                "材料清单：\r\n");
        for (Matter matter: matters) {

            detail.append(matter.scene().getDesc()).append("：").append(matter.brand()).append(

                    "、").append(matter.model()).append("、平⽶价格：").append(matter.price()).append(" 元。\n");
        }
        return detail.toString();
    }
}
